package com.prs.crm.domain.pm;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;

import com.prs.crm.domain.Attachment;
import com.prs.crm.domain.FlowEntity;
import com.prs.crm.domain.doc.Document;
import com.prs.crm.domain.hr.Person;

@Entity
@Table(name="pm_project")
public class PmProject extends FlowEntity{
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Integer id;
	private String title;
	@ManyToOne
	private Person principal;	
	@ManyToMany(fetch=FetchType.LAZY)
	@Cascade({org.hibernate.annotations.CascadeType.ALL,org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
	private Set<Person> manageGroup;
//	@ManyToMany(fetch=FetchType.LAZY)
//	@JoinTable(name = "pm_project_member", joinColumns = { @JoinColumn(name ="pm_project_id" )}, inverseJoinColumns = { @JoinColumn(name = "person_id") })
//	@Cascade({org.hibernate.annotations.CascadeType.ALL,org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
//	private Set<Person> memberGroup;
	@ManyToMany(fetch=FetchType.LAZY)
	@Cascade({org.hibernate.annotations.CascadeType.ALL,org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
	private Set<PmGroup> memberGroup;
	
	@Lob
	private String summary;
	private Date startTime;
	private Date endTime;
	@ManyToOne(fetch=FetchType.LAZY)
	@Cascade({org.hibernate.annotations.CascadeType.ALL,org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
	private Attachment attach;
	private String state;
	@OneToMany(fetch=FetchType.LAZY,mappedBy="project")
	private Set<PmStage> stages;
	private Double budget;
	@OneToMany(fetch=FetchType.LAZY,mappedBy="project")
	private Set<Document> docs;
	@ManyToOne
	private PmType type;
	@ManyToOne
	private PmSource source;
	
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public Set<Person> getManageGroup() {
		if(manageGroup == null) {
			manageGroup = new HashSet<Person>();
		}
		return manageGroup;
	}
	public void setManageGroup(Set<Person> manageGroup) {
		this.manageGroup = manageGroup;
	}
	public Set<PmGroup> getMemberGroup() {
		if(memberGroup == null) {
			memberGroup = new HashSet<PmGroup>();
		}
		return memberGroup;
	}
	public void setMemberGroup(Set<PmGroup> memberGroup) {
		this.memberGroup = memberGroup;
	}
	public String getSummary() {
		return summary;
	}
	public void setSummary(String summary) {
		this.summary = summary;
	}
	public Date getStartTime() {
		return startTime;
	}
	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}
	public Date getEndTime() {
		return endTime;
	}
	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}
	public Attachment getAttach() {
		return attach;
	}
	public void setAttach(Attachment attach) {
		this.attach = attach;
	}
	public String getState() {
		return state;
	}
	public void setState(String state) {
		this.state = state;
	}
	public void setStages(Set<PmStage> stages) {
		this.stages = stages;
	}
	public Set<PmStage> getStages() {
		return stages;
	}
	public void setBudget(Double budget) {
		this.budget = budget;
	}
	public Double getBudget() {
		return budget;
	}
	public void setDocs(Set<Document> docs) {
		this.docs = docs;
	}
	public Set<Document> getDocs() {
		return docs;
	}
	public void setPrincipal(Person principal) {
		this.principal = principal;
	}
	public Person getPrincipal() {
		return principal;
	}
	public void setType(PmType type) {
		this.type = type;
	}
	public PmType getType() {
		return type;
	}
	public void setSource(PmSource source) {
		this.source = source;
	}
	public PmSource getSource() {
		return source;
	}
	
}
